Component({
  properties: {
    data: {
      type: Object,
      default: {},
    },
    status: {
      type: Boolean,
      default: false,
    },
  },
  data: {
    cardData: {},
    slideButtons: [
      {
        // 侧滑菜单
        text: "详情",
      },
      {
        // 侧滑菜单
        text: "移动",
      },
      {
        // 侧滑菜单
        text: "置顶",
      },
      {
        type: "warn",
        text: "删除",
        extClass: "test",
      },
    ],
  },
  observers: {
    "data.**": function (field) {
      const xData = field;
      if (!xData.lastChapter.name) {
        xData.lastChapter = xData.chapter[xData.chapter.length - 1];
        this.setData({
          cardData: xData,
        });
      } else {
        this.setData({
          cardData: xData,
        });
      }
    },
  },
  lifetimes: {
    attached: function () {
      const xData = this.data.data;
      if (!xData.lastChapter.name) {
        xData.lastChapter = xData.chapter[xData.chapter.length - 1];
        this.setData({
          cardData: xData,
        });
      } else {
        this.setData({
          cardData: xData,
        });
      }
    },
  },
  // data.lastChapter.name
  methods: {
    goToContent(e) {
      this.triggerEvent("content", {
        id: e.currentTarget.dataset.id,
      });
    },
    slideButtonTap(e) {
      if (e.detail.index == 3) {
        // 删除
        this.triggerEvent("delete", {
          id: e.currentTarget.dataset.id,
        });
      } else if (e.detail.index == 2) {
        // 置顶
        this.triggerEvent("top", {
          id: e.currentTarget.dataset.id,
        });
      } else if (e.detail.index == 0) {
        // 详情
        this.triggerEvent("detail", {
          id: e.currentTarget.dataset.id,
        });
      } else if (e.detail.index == 1) {
        // 移动
        this.triggerEvent("move", {
          id: e.currentTarget.dataset.id,
        });
      }
    },
  },
});
